
import QQMapWX from '../map/qqmap-wx-jssdk.min';
let qqmapsdk = ""
export const openPage = function({ p_name,c_name,a_name ,address },_this) {
    qqmapsdk = new QQMapWX({
        key: 'M3LBZ-DPTHP-JN6DE-VZNGT-652OF-IBBNP'
    });
    let buildingAddress = p_name + c_name +a_name +address
        qqmapsdk.geocoder({
                address: buildingAddress, //要转化为经纬度的地址名称
                success: res => {
                    wx.showLoading({
                        title: '加载中...'
                    })
                    //res里包含了该地址的信息
                    let { location } = res.result
                    _this.setData({ location })
                    wx.openLocation({
                        latitude: location.lat,
                        longitude: location.lng,
                        scale: 18,
                        address: buildingAddress,
                        success: res => {
                            wx.hideLoading()
                        }
                    });
                },
                fail: res => {
                    //如果查不到这个地址就显示当前地址
                    wx.getLocation({
                        type: 'gcj02',
                        isHighAccuracy: true,
                        success: res => {
                            let { latitude, longitude } = res
                            wx.showToast({
                                title: '位置获取失败',
                                icon: "none"
                            })
                            wx.openLocation({ latitude, longitude, scale: 18, name: "当前位置" });
                        }
                    })
                }
            });
     
}